package com.tj.test.sys.controller;

import com.tj.test.sys.po.Questionpaper;
import com.tj.test.sys.service.impl.QuestionpaperService;
import com.tj.test.sys.tool.ResponseMessage;
import com.tj.test.sys.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("/Questionpaper")
@Api(tags = "Questionpaper")
public class QuestionpaperController {
    @Autowired
    private QuestionpaperService service;

    @ApiOperation("查询所有试卷考题表信息")
    @RequestMapping(value = "/selectAllQuestionpaper",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage selectAllQuestionpaper(){
        Map<String,List<Questionpaper>> map=new HashMap<>();
        List<Questionpaper> list=service.selectAllQuestionpaper();
        if (!list.isEmpty()){
            map.put("AllQuestionpaper",list);
            return Result.success("查询成功",map);
        }
        return Result.error("查询失败",false);
    }

    @ApiOperation("插入试卷考题表信息")
    @RequestMapping(value = "/insertQuestionpaper",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage insertQuestionpaper(Questionpaper questionpaper){
        int temp=0;
        if (questionpaper!=null){
            if (questionpaper.getQuestionpaperid()!=0){
                temp=service.insertQuestionpaper(questionpaper);
                if (temp>0) {return Result.success("插入试卷考题表信息成功",temp);}
                else  {return Result.error("该试卷考题表已存在",temp);}
            }
        }
        return Result.error("插入试卷考题表信息失败",temp);
    }

    @ApiOperation("删除试卷考题表信息")
    @RequestMapping(value = "/deleteQuestionpaper",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage deleteQuestionpaper(Questionpaper questionpaper){
        int temp=0;
        if (questionpaper!=null){
            if (questionpaper.getQuestionpaperid()!=0){
                temp=service.deleteQuestionpaper(questionpaper);
                if (temp>0) {return Result.success("删除试卷考题表信息成功",temp);}
                else {return Result.error("无该试卷考题表",temp);}
            }
        }
        return Result.error("删除试卷考题表信息失败",temp);
    }

    @ApiOperation("修改试卷考题表信息")
    @RequestMapping(value = "/updateQuestionpaper",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage updateQuestionpaper(Questionpaper questionpaper){
        int temp=0;
        if (questionpaper!=null){
            if (questionpaper.getQuestionpaperid()!=0){
                temp=service.updateQuestionpaper(questionpaper);
                if (temp>0) {return Result.success("更新试卷考题表信息成功",temp);}
                else {return Result.error("无该试卷考题表信息",temp);}
            }
        }
        return Result.error("更新试卷考题表信息失败",temp);
    }
}
